package com.ruoyi.project.information.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.models.auth.In;
import org.springframework.data.repository.query.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.information.domain.TbCustomers;
import com.ruoyi.project.information.service.ITbCustomersService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 客商基本信息Controller
 *
 * @author 萧雪
 * @date 2022-09-22
 */
@RestController
@RequestMapping("/information/tbCustomers")
public class TbCustomersController extends BaseController
{
    @Autowired
    private ITbCustomersService tbCustomersService;

    /**
     * 查询客商基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('information:tbCustomers:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbCustomers tbCustomers)
    {
        startPage();
        List<TbCustomers> list = tbCustomersService.selectTbCustomersList(tbCustomers);
        return getDataTable(list);
    }

    //根据客商类型查询ID
    @GetMapping("/CompanyTypeAll/{companyType}")
    public AjaxResult selectTbCustomerCompanyTypeAll(@PathVariable("companyType") Integer companyType){
        List<TbCustomers> tbCustomers = tbCustomersService.selectTbCustomerCompanyTypeAll(companyType);
        return AjaxResult.success(tbCustomers);
    }

    /**
     * 导出客商基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('information:tbCustomers:export')")
    @Log(title = "客商基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbCustomers tbCustomers)
    {
        List<TbCustomers> list = tbCustomersService.selectTbCustomersList(tbCustomers);
        ExcelUtil<TbCustomers> util = new ExcelUtil<TbCustomers>(TbCustomers.class);
        util.exportExcel(response, list, "客商基本信息数据");
    }

    /**
     * 获取客商基本信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('information:tbCustomers:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tbCustomersService.selectTbCustomersById(id));
    }

    /**
     * 新增客商基本信息
     */
    @PreAuthorize("@ss.hasPermi('information:tbCustomers:add')")
    @Log(title = "客商基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbCustomers tbCustomers)
    {
        return toAjax(tbCustomersService.insertTbCustomers(tbCustomers));
    }

    /**
     * 修改客商基本信息
     */
    @PreAuthorize("@ss.hasPermi('information:tbCustomers:edit')")
    @Log(title = "客商基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbCustomers tbCustomers)
    {
        return toAjax(tbCustomersService.updateTbCustomers(tbCustomers));
    }

    /**
     * 删除客商基本信息
     */
    @PreAuthorize("@ss.hasPermi('information:tbCustomers:remove')")
    @Log(title = "客商基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbCustomersService.deleteTbCustomersByIds(ids));
    }
}
